<template>
  <!-- dropdown
           默认插槽：默认显示内容
           具名插槽：dropdown
                    下拉 的菜单
                el-dropdown-menu
                   el-dropdown-item
       this.$i18n.locale===zh

 -->

  <el-dropdown @command="commandEvent">
    <span class="color">
      <svg-icon icon-class="language" />
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item
          :disabled="$i18n.locale === 'zh'"
          command="zh"
        >中文</el-dropdown-item>
        <el-dropdown-item
          command="en"
          :disabled="$i18n.locale === 'en'"
        >english</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>
<script>
import jsCookie from 'js-cookie'
export default {
  name: 'Lang',
  methods: {
    commandEvent(command) {
      // 切换语言
      this.$i18n.locale = command
      //   存储当前语言标识 到浏览器
      jsCookie.set('setLang', command)
      //   刷新当前网站
      this.$router.go(0)
    }
  }
}
</script>
<style lang="scss" scoped>
.color {
  color: #fff;
  margin-right: 20px;
}
</style>
